package com.example.helloffmpeg

import android.app.Application
import com.example.helloffmpeg.system.FfmpegHelper
import com.example.helloffmpeg.util.LogU
import xcrash.XCrash

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        FfmpegHelper.init()
        initXcrash()
    }

    private fun initXcrash() {
        val params: XCrash.InitParameters = XCrash.InitParameters()

        // 通用配置
        params.setPlaceholderSizeKb(128)
            .setLogFileMaintainDelayMs(5000)
            .setLogDir("${filesDir}/CrashLog")

        // Java 崩溃配置
        params.setJavaRethrow(true)
            .setJavaDumpFds(true)
            .setJavaCallback { logPath, emergency ->
                LogU.i(
                    "initXcrash~Java异常文件路径: $logPath ,emergency:$emergency"
                )
            }

        // Native 崩溃配置
        params.setNativeRethrow(true)
            .setNativeCallback { logPath, emergency ->
                LogU.i(
                    "initXcrash~Native异常文件路径: $logPath ,emergency:$emergency"
                )
            }

        // ANR 配置
        params.setAnrCallback { logPath, emergency ->
            LogU.i(
                "initXcrash~ANR异常文件路径: $logPath ,emergency:$emergency"
            )
        }
        XCrash.init(this, params)
    }
}